define(window.backboneCommon.getViewDefine("targets.time"), function ($,require,Collection,tpl) {
    var defaultsOptions={
        listSelect:{},
        submitCallback:null
    };
    var pagePrivate = {
        getDefaults :function () {
            return defaultsOptions
        },
        getOptions : function (options) {
            options=$.ExtCommon.isCheckEmpty(options)?{}:options;
            return $.ExtCommon.initMergeJson(this.getDefaults(),options);
        }
    };
    var backboneView= Backbone.View.extend({
        events: {
            "click #submit_modal_targetTime": "saveSubmit"
        },
        initialize: function () {
            this.render();
        },
        render:function(){
            var templateHtml=_.template(tpl);
            this.$el.html(templateHtml());
            return this;
        },
        initMain:function(options){
            this.elementModel={
                time:$('#panel_modal_targetTime'),
                modal:$('#modal_targetTime')
            };
            this.extObject={};
            this.pageData={initPage:false};
            this.pageOptions=$.ExtCommon.initMergeJson(pagePrivate.getOptions(),options);
        },
        initPage:function (json) {
            var self=this;
            json=$.ExtCommon.isCheckEmpty(json)?{}:json;
            if(!self.pageData.initPage){
                self.pageData.initPage=true;
                self.extObject.time=self.elementModel.time.ExtWeekHour({initValue:json,
                    initCallback:function(){self._showModal();}
                });
            }else{
                self.extObject.time.setSelected(json);
            }
            self._showModal();
        },
        _checkForm:function () {},
        saveSubmit:function () {
            this._hideModal();
            var jsonData=this.extObject.time.getSelectedHtml();
            if(this.pageOptions.submitCallback){this.pageOptions.submitCallback(jsonData);}
        },
        _showModal:function(){
            this.elementModel.modal.modal("show");
            $.ExtAssist.modal.computeTop(this.elementModel.modal);
        },
        _hideModal: function () {
            this.elementModel.modal.modal("hide");
        }
    });
    var viewModel=function(options){
        this.collection= new Collection();
        this.model=this.collection.model;
        this.view=new backboneView({el:options.pElement,collection:this.collection,model:this.model});
        this.view.initMain(options);
    };
    viewModel.prototype={
        init:function (json) {
            this.view.initPage(json);
        }
    };
    return viewModel;
});